<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="utils.js"></script>
<script src="session-storage-utils.js"></script>
<script>
RunSessionStorageTest(async (isPrerendering, url, prerenderChannel, done) => {
  if (!isPrerendering) {
    startPrerendering(url);
    // Wait for the message from the prerendering page.
    assert_equals(
        await getNextMessage(prerenderChannel),
        'From prerendering page 1')

    // Add an item to the session storage.
    sessionStorage.setItem('set by initiator page', '1');

    // Send the message to the prerendering page.
    prerenderChannel.postMessage('From initiator page');

  } else {
    sessionStorage.setItem('set by prerendering page', '1');

    // Send the message to the initiator page.
    prerenderChannel.postMessage('From prerendering page 1');

    // Wait for the message from the initiator page.
    assert_equals(
        await getNextMessage(prerenderChannel),
        'From initiator page');

    assert_equals(
        getSessionStorageKeys(),
        'set by prerendering page',
        'The session storage item added by the initiator page after the ' +
        'prerendering page accessed the session storage must not be visible ' +
        'in the prerendering page.');
    done();
  }
});
</script>
